package cn.snorlaxzjt.LBSserver.mapper;

import cn.snorlaxzjt.LBSserver.po.entity.Comment;
import cn.snorlaxzjt.LBSserver.po.page.CommentPage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CommentMapper extends BaseMapper<Comment> {

    @Select("<script>"
            +"select * from comment left join user u on u.id = comment.user_id where moment_id  in ("
            +"<foreach collection='list' item='id' separator=','>"
            +"#{id}"
            +"</foreach>) and status = 1 order by create_time asc"
            +"</script>")
    List<CommentPage> queryByCommentIds(@Param(value = "list") List<Long> commentIds);

    @Select("update comment set status = 0 where id = #{id}")
    void del(Long id);

    @Select("select * from comment left join user u on u.id = comment.user_id " +
            "where moment_id = #{id}  and status = 1 order by create_time asc")
    List<CommentPage> selectByMomentId(Long id);
}
